From: Dan Winship Date: Wed, 4 May 2011 15:15:45 +0000 (-0400) Subject: messageTray: improve bad-markup handling X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~1013^2^2~8022 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=7542e68b6fca5ad02459576b350149c97743675b;p=gnome-shell.git messageTray: improve bad-markup handling _fixMarkup() was supposed to be ensuring that the markup we passed to clutter was correct, but it was validating the syntax incorrectly, and wasn't checking that the markup was valid (or even well-formed). This is bad because if you pass bad pango markup to clutter_text_set_markup(), it will g_warn and drop the string on the floor. Fix by fixing up the regexps, and then calling Pango.parse_markup() on the result, and just xml-escaping everything if parse_markup() fails. https://bugzilla.gnome.org/show_bug.cgi?id=650298 --- diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js index 41475c106..4dc949e32 100644 --- a/js/ui/messageTray.js +++ b/js/ui/messageTray.js @@ -68,14 +68,19 @@ function _fixMarkup(text, allowMarkup) { // Support &, ", ', < and >, escape all other // occurrences of '&'. let _text = text.replace(/&(?!amp;|quot;|apos;|lt;|gt;)/g, '&'); + // Support , , and , escape anything else // so it displays as raw markup. - return _text.replace(/<(\/?[^biu]>|[^>\/][^>])/g, '<$1'); - } else { - // Escape everything - let _text = text.replace(/&/g, '&'); - return _text.replace(/)/g, '<'); + + try { + Pango.parse_markup(_text, -1, ''); + return _text; + } catch (e) {} } + + // !allowMarkup, or invalid markup + return GLib.markup_escape_text(text, -1); } function URLHighlighter(text, lineWrap, allowMarkup) {